/**
 emma_project
    Copyright (C) 2015  Rodrigo Garcia

 This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "usartio.h" 

int usart_putchar(char c, FILE *stream) {
	if (c == '\n'  )
	  usart_tx('\r'); 
	usart_tx(c);
	return 0;
}

int usart_getchar(FILE *stream){
	int c;
	c=usart_rx();
	if(c=='\r') c='\n';
	usart_tx(c);	//eco
	return c;
}

// ********** stdio.h declarations ****************

/* printf and scanf is included */
//FILE usart=FDEV_SETUP_STREAM(usart_putchar,usart_getchar,_FDEV_SETUP_RW); 

/* printf is included */
FILE usart=FDEV_SETUP_STREAM(usart_putchar,NULL,_FDEV_SETUP_WRITE);
// ************************************************

void usart_printf_init(void){
	usart_init();
	stdout=&usart;
	stdin=&usart; // to avoid use scanf (too much mem) ?
}

